package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author：XueShiHao
 * @Date：2025/6/20 星期五 18:44:42
 * @Email:747278007@qq.com
 * @Description:
 **/
@Api("用户对购物车的操作")
@Slf4j
@RestController
@RequestMapping(" /user/shoppingCart")
public class ShoppingCartController{
    @Autowired
    private ShoppingCartService shoppingCartService;
    @ApiOperation("删除购物车中的一个商品")
    @PostMapping("/sub")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("要删除的商品：{}",shoppingCartDTO);
        shoppingCartService.subShoppingCart(shoppingCartDTO);
        return Result.success();
    }
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>>  find(){

        return Result.success(shoppingCartService.showShoppingCart());
    }
    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<String> add(@RequestBody ShoppingCartDTO shoppingCartDTO){
       shoppingCartService.addShoppingCart(shoppingCartDTO);
       return Result.success();
    }
    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
public Result<String> cleanAll(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }

}